package regiongenerator.data;

import java.util.List;

/**
 *
 * @author Daniel Grimm
 */
public class FieldConstraint {

    private List<Integer>   allowedTypes;
    private Interval        allowedElevations;

    public FieldConstraint(List<Integer> types, Interval elevations)
    {
        allowedTypes = types;
        allowedElevations = elevations;
    }

    public void addConstraint(FieldConstraint newConstraint)
    {
        /*
         * Altitudes
         */
        if (newConstraint.getAllowedElevations().getLeft() > allowedElevations.getLeft())
            allowedElevations.setLeft(newConstraint.getAllowedElevations().getLeft());
        if (newConstraint.getAllowedElevations().getRight() < allowedElevations.getRight())
            allowedElevations.setRight(newConstraint.getAllowedElevations().getRight());

        /*
         * FieldTypes
         */

        allowedTypes.retainAll(newConstraint.allowedTypes);
    }

    public boolean checkAgainst(int type, int elevation)
    {
        boolean typeAllowed = allowedTypes.contains(type);

        return typeAllowed &&
                (elevation<allowedElevations.getRight()) &&
                (elevation>allowedElevations.getLeft());
    }

    /**<editor-fold desc="getters">
     *
     * @return the allowedTypes
     */
    public List<Integer> getAllowedTypes() {
        return allowedTypes;
    }

    /**
     * @return the allowedElevations
     */
    public Interval getAllowedElevations() {
        return allowedElevations;
    }
    //</editor-fold>
}
